package com.fitmanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fitmanagement.entity.Dietplans;
import com.fitmanagement.entity.Exercises;
import com.fitmanagement.mapper.ExercisesMapper;
import com.fitmanagement.service.IExercisesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 虚空
 * @since 2024-10-25
 */
@Service
public class ExercisesServiceImpl extends ServiceImpl<ExercisesMapper, Exercises> implements IExercisesService {


    @Override
    public Boolean removeByexercisesId(int id) {
        QueryWrapper<Exercises> queryWrapper = new QueryWrapper<>();
        QueryWrapper<Exercises> exerciseID = queryWrapper.eq("ExerciseID", id);
        return this.remove(exerciseID);
    }

    @Override
    public List<Map<String, Object>> SearchByName(String exercisename) {
        QueryWrapper<Exercises> queryWrapper = new QueryWrapper<>();
        QueryWrapper<Exercises> like = queryWrapper.like("ExerciseName", exercisename);
        return this.listMaps(like);

    }

    @Override
    public Boolean updateStatusById(Integer id, Integer status) {
        QueryWrapper<Exercises> queryWrapper = new QueryWrapper<>();
        QueryWrapper<Exercises> exerciseID = queryWrapper.eq("ExerciseID", id);
        Exercises exercises = this.getOne(exerciseID);
        if (exercises != null){
            exercises.setStatus(status);
            return this.updateById(exercises);
        }
        return false;

    }

}
